#ifndef STATICQUEUE_H
#define STATICQUEUE_H

#include "Queue.h"
#include "Exception.h"

namespace DSLib
{

template <typename T, int N>
class StaticQueue : public Queue<T>
{
protected:
	T m_space[N];
	int m_front;
	int m_rear;
	int m_length;
public:
	StaticQueue()
	{
		m_front = 0;
		m_rear = 0;
		m_length = 0;
	}

	int capacity() const
	{
		return N;
	}

	void add(const T& e)
	{
		if (m_length < capacity())
		{
			m_space[m_rear] = e;
			m_rear = (m_rear + 1) % capacity();
			m_length++;
		}
		else
		{
			THROW_EXCEPTION(InvaildParameterException, "no space to add element!");
		}
	}

	void remove()
	{
		if (m_length > 0)
		{
			m_front = (m_front + 1) % capacity();
			m_length--;
		}
		else
		{
			THROW_EXCEPTION(InvaildParameterException, "no element to be removed!");
		}
	}

	T front() const
	{
		if (m_length > 0)
		{
			return m_space[m_front];
		}
		else
		{
			THROW_EXCEPTION(InvaildParameterException, "no element in current space!");
		}
	}

	void clear()
	{
		m_front = 0;
		m_rear = 0;
		m_length = 0;
	}

	int length() const
	{
		return m_length;
	}
};
}





#endif